//
//  KLManageGesturePasswordViewController.m
//  KISSLOCK
//
//  Created by 华杨科技 on 2017/4/25.
//  Copyright © 2017年 陈宾鹏. All rights reserved.
//
//  手势密码管理TableViewController

#import "KLManageGesturePasswordViewController.h"
#import "HemaConst.h"
#import "KLHelp.h"
#import "KLResetGesturePwdViewController.h"
#import "KLGesturePwdViewController.h"
#import "KLManageWithoutpwdController.h"



@interface KLManageGesturePasswordViewController () <UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation KLManageGesturePasswordViewController

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    }
    return _tableView;
}

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavAndInitTableView];
    
}

- (void)setNavAndInitTableView {
    self.title = @"手势密码管理";
    
    self.view.backgroundColor = RGB_UI_COLOR(242, 242, 242);

    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.tableFooterView = [UIView new];
    [self.view addSubview:self.tableView];
    
    self.dataArray = @[@"免密管理",@"修改手势密码",@"重设手势密码"].mutableCopy;
    
    [KLHelp navSet:self doBackHandeler:^(UIButton *backButton) {
        [backButton addTarget:self action:@selector(doBack:) forControlEvents:(UIControlEventTouchUpInside)];
    }];
} - (void)doBack:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentififer = @"cellIdentififer";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentififer];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:cellIdentififer];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = self.dataArray[indexPath.section];
    
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section==0) {
        NSLog(@"0:%@",[NSString stringWithFormat:@"%ld--%ld",(long)indexPath.section,(long)indexPath.row]);
        KLManageWithoutpwdController *withoutPwdVC = [[KLManageWithoutpwdController alloc] init];
                [self.navigationController pushViewController:withoutPwdVC animated:YES];
        
    }else if (indexPath.section ==1){

        KLGesturePwdViewController *pwdVC = [[KLGesturePwdViewController alloc] init];
        
        [self presentViewController:pwdVC animated:YES completion:nil];
        
    }else {
        // 需要先判断是否设置手势密码，是 原密码-》新密码 -》新确认密码
        // 否  新密码一次--》新密码二次
        KLResetGesturePwdViewController *resetVC = [[KLResetGesturePwdViewController alloc] initWithNibName:@"KLResetGesturePwdViewController" bundle:[NSBundle mainBundle]];
        [self.navigationController pushViewController:resetVC animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}


@end
